/**
 * 0208
 *  
 * @Author : Ruoyu Wang
 * @DateTime : 24-11-11 下午6:05
 */

#include <iostream>
#include <vector>
#include <algorithm>

using namespace std;

struct Node {
    vector<Node *> childs = vector<Node *>(26, nullptr);
    bool isEnd = false;

    Node() {
    }

    Node(int x) {
        childs[x] = new Node;
    }
};

class Trie {
private:
    Node *root;
public:
    Trie() {
        root = new Node;
    }

    void insert(string word) {
        Node *p = root;
        for (char i: word) {
            int x = i - 'a';
            if (p->childs[x] == nullptr) {
                p->childs[x] = new Node;
            }
            p = p->childs[x];
        }
        p->isEnd = true;
    }

    bool search(string word) {
        Node *p = root;
        for (char i: word) {
            int x = i - 'a';
            if (p->childs[x] == nullptr) {
                return false;
            }
            p = p->childs[x];
        }
        return p->isEnd;
    }

    bool startsWith(string prefix) {
        Node *p = root;
        for (int i = 0; i < prefix.size(); ++i) {
            int x = prefix[i] - 'a';
            if (p->childs[x] == nullptr) {
                return false;
            }
            p = p->childs[x];
        }
        return true;
    }
};

int main() {
    Trie trie;
    trie.insert("apple");
    cout << trie.search("apple");
    return 0;
}